import Vue from 'vue'
import App from './App.vue'
import router from './router'
import { registerApplication, start } from 'single-spa'
Vue.config.productionTip = false

function load(url){
  return new Promise((resolve,reject)=>{
    let script = document.createElement('script')
    script.src = url
    script.onload = resolve;
    script.onerror = reject;
    document.body.appendChild(script)
  })
}

registerApplication('childApplication',
  async () => {
    console.log('激活～～');
    await load('http://localhost:10000/js/chunk-vendors.js');
    await load('http://localhost:10000/js/app.js');
    return window.childApplication
  },
  /** 当路由匹配时，激活我的子应用 */
  location => location.pathname.startsWith('/vue'),
  /** 可以传递一个自定义属性，该属性可以是对象或者方法，该属性会传递给子应用的三个接口 */
  { customProps: {} }
)
start()

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
